/*
 * ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
 * Without permission, no one has the right to obtain, disclose or use this software in any way.
 */
package com.ecarx.systemui.plugin.ui.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.PixelFormat
import android.util.Log
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import com.ecarx.systemui.plugin.AppConstants
import com.ecarx.systemui.plugin.R
import com.ecarx.systemui.plugin.utils.LogUtils

class ErrorInfoDialog : Dialog {

    companion object {
        private const val TAG = "ErrorInfoDialog"
    }

    private var title: String? = null
    private var content: String? = null
    constructor(context: Context?, title: String, content: String) : super(context!!, R.style.PluginDialog) {
        this.title = title
        this.content = content
        init()
    }
    constructor(context: Context?, themeResId: Int) : super(
        context!!, themeResId
    ) {
        init()
    }

    private fun init(){
        initConfig()
        setContentView(R.layout.dialog_error_info)
        initView()
    }

    private fun initConfig() {
        LogUtils.d(TAG, "initConfig: ")
        if (window != null) {
            val params = WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT,
                AppConstants.PLUGIN_DIALOG_TYPE,
                WindowManager.LayoutParams.FLAG_FULLSCREEN or
                        WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or
                        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                PixelFormat.TRANSPARENT
            )
            params.gravity = Gravity.CENTER
            window?.attributes = params
            setCanceledOnTouchOutside(false)
        }
    }

    private fun initView() {
        findViewById<TextView>(R.id.tv_title).text = title
        findViewById<TextView>(R.id.tv_desc).text = content
        findViewById<View>(R.id.btn_confirm).setOnClickListener {
            dismiss()
        }
    }
}